<template>
	<view class="margin-top bg-white padding-lr">
		<u-form :model="info" ref="form" label-width="auto">
			<u-form-item label="登录名" prop="loginName" required><u-input v-model="info.loginName" /></u-form-item>
			<u-form-item label="密码" prop="password"><u-input v-model="info.password" /></u-form-item>
			<u-form-item label="姓名" prop="realName"><u-input v-model="info.realName" /></u-form-item>
			<u-form-item label="手机号" prop="mobile"><u-input v-model="info.mobile" /></u-form-item>
			<u-form-item label="昵称" prop="nickName"><u-input v-model="info.nickName" /></u-form-item>
			<u-form-item label="编号" prop="userCode"><u-input v-model="info.userCode" /></u-form-item>
			<u-form-item label="证件号码" prop="cardId"><u-input v-model="info.cardId" /></u-form-item>
			<u-form-item label="居住地址" prop="address"><u-input v-model="info.address" /></u-form-item>
			<u-form-item label="邮箱" prop="email"><u-input v-model="info.email" /></u-form-item>
			<u-form-item label="序号" prop="sequence"><u-input v-model="info.sequence" type="number" /></u-form-item>
			<view class="padding-tb"><u-button type="primary" @click="save">保存</u-button></view>
		</u-form>
	</view>
</template>

<script>
export default {
	onLoad: function(option) {
		if (option.info) {
			this.info = JSON.parse(decodeURIComponent(option.info));
		} else {
			this.info.orgId = option.orgId || '';
		}
	},
	onReady: function() {
		this.$refs.form.setRules(this.rules);
	},
	data() {
		return {
			info: {
				id: '',
				orgId: '',
				loginName: '', // 登录名
				sexCode: 'UNKNOWN', //默认性别未知
				sequence: "0" // 序号
			},
			rules: {
				loginName: [{ required: true, message: '必填', trigger: ['change', 'blur'] }]
			}
		};
	},
	methods: {
		// 保存用户
		save: function() {
			if (!this.info.orgId) {
				this.$utils.showToast('无效的组织ID');
				return;
			}
			this.$refs['form'].validate(valid => {
				if (valid) {
					this.$request.post(
						'/admin/sys/user/save',
						this.info,
						res => {
							this.$utils.showModal('保存成功！', () => {
								uni.navigateBack({
									delta: 1
								});
							});
						},
						true,
						true,
						true
					);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped></style>
